package com.kejiguan.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.MenuItem;

import java.util.List;

/**
 * Created by YYY on 2016/5/1.
 */
public class UserInfoMenuAdapter extends BaseAdapter {


    private Context context;
    private List<MenuItem> menuItems;
    private LayoutInflater inflater;


    public UserInfoMenuAdapter(Context context, List<MenuItem> menuItems) {
        this.context = context;
        this.menuItems = menuItems;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (null == menuItems) {
            return 0;
        } else {
            return menuItems.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MenuItem menuItem = menuItems.get(position);

        if (null == convertView) {
            convertView=inflater.inflate(R.layout.fragment_user_info_menu_item_layout,null);
        }

        ((TextView) convertView.findViewById(R.id.menu_name)).setText(menuItem.getLabel());
        return convertView;
    }
}
